package com.rchat.pocmini.util;

import java.util.List;

/**
 * Created by ljd on 2017/4/19.
 */

public class ListUtil {

    public static <T> boolean isInList(List<T> classList, T clazz) {
        if (classList == null || clazz == null) {
            return false;
        }
        for (int i = 0; i < classList.size(); i++) {
            T clz = classList.get(i);
            if (clz == clazz) {
                return true;
            }
        }
        return false;
    }

    public static <T> void add(List<T> classList, T clazz) {
        if (classList == null || clazz == null) {
            return;
        }
        if (isInList(classList, clazz)) {
            return;
        }
        classList.add(clazz);
    }

    public static <T> void remove(List<T> classList, T clazz) {
        if (classList == null || clazz == null) {
            return;
        }
        for (int i = 0; i < classList.size(); i++) {
            T clz = classList.get(i);
            if (clz == null) {
                break;
            }
            if (clz == clazz) {
                classList.remove(i);
                return;
            }
        }
    }
}
